<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8" />
		<title></title>
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<link rel="stylesheet" type="text/css" href="css/releaseOrder.css"/>
		<link rel="stylesheet" type="text/css" href="css/lyz.calendar.css"/>
		<script src="js/jquery-2.1.0.js" type="text/javascript" charset="utf-8"></script>
		<script src="js/lyz.calendar.min.js" type="text/javascript" charset="utf-8"></script>
	</head>
	<body>
<script> 
	function checkInt(o){ 
		theV=isNaN(parseInt(o.value))?0:parseInt(o.value); 
		if(theV!=o.value){o.value=theV;} 
			txtTotal.value=goodsnum.value*goodsPrice.value; 
	}
	function checkP(o){ 
		theV=isNaN(parseFloat(o.value))?0:parseFloat(o.value); 
		theV=parseInt(theV*100)/100; 
		if(theV!=o.value){ 
			theV=(theV*100).toString(); 
			theV=theV.substring(0,theV.length-2)+"."+theV.substring(theV.length-2,theV.length) 
			o.value=theV; 
	} 
	txtTotal.value=goodsnum.value*goodsPrice.value; 
} 
</script> 
		<div id="head">  
			<a href=”#” onClick="javascript :history.back(-1);"> <img class="img_return" src="img/return.png"/> </a>
			<span class="head_txt">发布订单</span>
		</div>
		
		<div id="msg_box">
			
			<input type="text" name="goodsName" id="goodsName" value="" placeholder="    请输入购买商品名称"/><br />
			<input type="text" name="originPlace" id="originPlace" value="" placeholder="    请输入商品所在地"/><br />
			<input type="number" name="goodsPrice" id="goodsPrice" value="" placeholder="    请输入单价并选择单位" onkeyup="checkP(this);" onpaste="checkP(this);" oncut="checkP(this);" ondrop="checkP(this);" onchange="checkP(this);" />
			<select name="danwei" id="danwei">
				<option value="1" selected="selected">kg</option>
				<option value="2">袋</option>
			</select>
			<br />
			<br />
			
			<input type="number" name="goodsnum" id="goodsnum" value="" placeholder="    请输入商品数量/重量" onkeyup="checkInt(this);" onpaste="checkInt(this);" oncut="checkInt(this);" ondrop="checkInt(this);" onchange="checkInt(this);"/> 
			<span style="font-size: 16px;position: relative;left: 6%;top: -20px;">商品总价：</span><input id="txtTotal" value="0" readonly>
			<input type="text" name="goodtime" id="goodtime" value="" placeholder="    请输入交易截止时间：如：17-12-03"/>
			<input type="text" name="phone" id="phone" value="" placeholder="    请输入您的联系电话"/>
			<span class="dizhi_txt"> 请选择您的地址：</span>
			<select name="dizhi" id="dizhi">
				<!--<option value="1" selected="selected">四川省成都市</option>-->
				<!--<option value="2">四川省自贡市</option>-->
				<!--<option value="3">四川省绵阳市</option>-->
			</select>
			<br />
			<div id="while_010">

			</div>
			<input type="button" name="goodsSub" id="goodsSub1" value="发布" />
		</div>
	</body>
	<script>      //  截止时间JQ 
    $(function () {
        $("#txtBeginDate").calendar({
            controlId: "divDate",                                 // 弹出的日期控件ID，默认: $(this).attr("id") + "Calendar"
            speed: 200,                                           // 三种预定速度之一的字符串("slow", "normal", or "fast")或表示动画时长的毫秒数值(如：1000),默认：200
            complement: true,                                     // 是否显示日期或年空白处的前后月的补充,默认：true
            readonly: true,                                       // 目标对象是否设为只读，默认：true
            upperLimit: new Date(),                               // 日期上限，默认：NaN(不限制)
            lowerLimit: new Date("2011/01/01"),                   // 日期下限，默认：NaN(不限制)
            callback: function () {                               // 点击选择日期后的回调函数
                alert("您选择的日期是：" + $("#txtBeginDate").val());
            }
        });
        $("#txtEndDate").calendar();
    });
</script>
	<script>
		$.ajax("/fengwei/PreOrder/getAddress",{
			type:"get",
			data:{
			},
			success:function(data){
				console.log(data)
				var dataObj = eval('('+data+')');
				var select = $("#dizhi");
				for(var i = 0;i<dataObj.length;i++){
					select.append("<option value='"+dataObj[i].adressId+"'>"+dataObj[i].goodsAdress+"</option>")
				}
				select.append("<option value='"+010+"'>另加地址</option>")
			},
			error:function(){
				alert(0)
			}
		})

		$(function(){
			var Dizhi = $("#dizhi option:selected").text();
			if(Dizhi==010){
				var oto = $("#while_010")
				oto.append("<input type='text' name='newAddress' id='newAddress' placeholder=' 请输入您的新收货地址'/>")
			}
		})

		
			var sub = $("#goodsSub1");
			sub.click(function(){
				var name = $("#goodsName").val();
				var place = $("#originPlace").val();
				var price = $("#goodsPrice").val();
				var danWei = $("#danwei option:selected").text();
				var sum = $("#goodsnum").val();
				var total = $("#txtTotal").val();
				var time = $("#goodtime").val();
				var Phone = $("#phone").val();
				var address;
				var Dizhi1 = $("#dizhi option:selected").text();
				if(Dizhi1==010){
					address = $("#newAddress").val();
				}else{
					address =$("#dizhi option:selected").text();
					var addressObj = $("#dizhi option:selected");
				}
				$.ajax("/fengwei/PreOrder/push",{
					type:"post",
					data:{
						'preorderCity':place,
						'preorderName':name,
						'preorderCount':sum,
						'preorderPhone':Phone,
						'preorderAdess':address,
						'preorderCuttime':time,
						'preoderPrice':price,
						'preoderUnit':danWei,
						'preoderTotalprice':total
					},
					success:function(){
						javascript :history.back(-1);
					},
					error:function(){
						alert(0)
					}
				})
			})
	
	</script>
</html>
